package com.mars.miaosha.service;

import com.mars.miaosha.dao.GoodsDao;
import com.mars.miaosha.domain.Goods;
import com.mars.miaosha.domain.MiaoshaGoods;
import com.mars.miaosha.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品的Service
 * @author MARS
 * @date 2018/5/9
 */
@Service
public class GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    public List<GoodsVo> getGoodsList(){
        return goodsDao.getGoodsVoList();
    }


    public GoodsVo getGoodsByGoodsId(long goodsId) {
        return goodsDao.getGoodsByGoodsId(goodsId);
    }

    public void reduceStock(GoodsVo goodsVo) {
        MiaoshaGoods goods = new MiaoshaGoods();
        goods.setGoodsId(goodsVo.getId());
        goods.setStockCount(goodsVo.getGoodsStock());
        goodsDao.reduceStock(goods);
    }
}
